﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Index.Master" Inherits="System.Web.Mvc.ViewPage<Langben.DAL.Cemetery>" %>

<%@ Import Namespace="Common" %>
<%@ Import Namespace="Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    墓位定价
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <div>
        <div id="dlg" class="easyui-dialog" title="修改定价" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        areaDingJiaSave();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#dlg').dialog('close');
                    }
                }]
            ">

            <table style="width: 300px;">
                <tr>
                    <td>区域选择:</td>
                    <td>
                        <%=Html.DropDownListFor(model => model.Yuan,Models.SysFieldModels.GetArea("Area","Yuan"),"请选择")%>
                        <select id="Pian" name="Pian">
                        </select>
                        <select id="Qu" name="Qu">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>销售价格:</td>
                    <td>
                        <input id="price" class="easyui-numberbox" type="text" name="price" data-options="required:true" />
                    </td>
                </tr>
            </table>
        </div>

        <div id="muxingdlg" class="easyui-dialog" title="新增排号" style="padding: 10px"
            data-options="
                iconCls: 'icon-save',
        modal:true ,
                buttons: [{
                    text:'保存',
                    iconCls:'icon-ok',
                    handler:function(){
                        muxingDingJiaSave();
                    }
                },{
                    text:'取消',
                    handler:function(){
                         $('#muxingdlg').dialog('close');
                    }
                }]
            ">

            <table style="width: 300px;">
                <tr>
                    <td>区域选择:</td>
                    <td>
                        <select id="muxingyuan" name="muxingyuan">
                        </select>
                        <select id="muxingpian" name="muxingpian">
                        </select>
                        <select id="muxingqu" name="muxingqu">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>墓型选择:</td>
                    <td>
                        <select id="muxing"></select>
                    </td>
                </tr>
                <tr>
                    <td>销售价格:</td>
                    <td>
                        <input id="muxingprice" class="easyui-numberbox" type="text" name="muxingprice" data-options="required:true" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript" language="javascript">
        $(function () {
            $('#flexigridData').datagrid({
                title: '墓位列表', //列表的标题
                iconCls: 'icon-site',
                width: 'auto',
                height: 'auto',
                nowrap: false,
                striped: true,
                collapsible: true,
                url: '../Cemetery/GetData', //获取数据的url
                sortName: 'RowGuid',
                sortOrder: 'desc',
                idField: 'RowGuid',
                toolbar: [

                      {
                          text: '区域定价',
                          iconCls: 'icon-edit',
                          handler: function () {
                              return areaDingJia();
                          }
                      },
                 {
                     text: '墓型区域定价',
                     iconCls: 'icon-edit',
                     handler: function () {
                         return muxingdingjia();
                     }
                 }
                , {
                    text: '单墓定价',
                    iconCls: 'icon-edit',
                    handler: function () {
                        return danmudingjia();
                    }
                }],
                columns: [[
					{ field: 'Hao', title: '<%: Html.DisplayNameFor(model => model.Hao) %>', width: 135 }
					, { field: 'Pai', title: '<%: Html.DisplayNameFor(model => model.Pai) %>', width: 135 }
					, { field: 'ShapeGuid', title: '<%: Html.DisplayNameFor(model => model.ShapeGuid) %>', width: 135 }
					, { field: 'Price', title: '<%: Html.DisplayNameFor(model => model.Price) %>', width: 135 }
					, { field: 'IsYanShou', title: '<%: Html.DisplayNameFor(model => model.IsYanShou) %>', width: 135 }
                ]],
                pagination: true,
                rownumbers: true

            });

            var parent = window.dialogArguments; //获取父页面
            if (parent == "undefined" || parent == null) {
                //    不是在iframe中打开的
            } else {
                //隐藏所有的按钮和分隔符
                $(".l-btn.l-btn-plain").hide();
                $(".datagrid-btn-separator").hide();
                //添加选择按钮
                $('#flexigridData').datagrid("addToolbarItem", [{ "text": "选择", "iconCls": "icon-ok", handler: function () { flexiSelect(); } }]);
            }
            getPian("#Pian");
            $("#Yuan").change(function () { getPian("#Pian"); });

            getQu("#Qu");
            $("#Pian").change(function () { getQu("#Qu"); });

            $('#dlg').dialog('close');
            $('#muxingdlg').dialog('close');
            $('#muxingyuan').empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($('#muxingyuan'));
            $.ajax({
                url: "../Area/GetYuan",
                type: "Post",
                GetYuan
                : "json",
                success: function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        
                        $("<option></option>")
                            .val(item["Id"])
                            .text(item["MyTexts"])
                            .appendTo($('#muxingyuan'));
                    });
                }
            });

            getmuxingpian("#muxingpian");
            $("#muxingyuan").change(function () { getmuxingpian("#muxingpian"); });

            getmuxingqu("#muxingqu");
            $("#muxingpian").change(function () { getmuxingqu("#muxingqu"); });

        });
        function getPian(Pian) {
            $(Pian).empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($(Pian));
            bindAreaDropDownList(Pian, "#Yuan");
            $(Pian).change();
        }

        function getQu(Qu) {
            $(Qu).empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($(Qu));
            bindAreaDropDownList(Qu, "#Pian");
            $(Qu).change();
        }
        function bindAreaDropDownList(id, parentid) {

            if ($(parentid).val() != "") {

                var url = "../Home/GetAreaByParent";
                $.ajaxSetup({ cache: false });
                $.getJSON(url, { id: id.substring(1), parentid: parentid.substring(1), value: $(parentid).val() }, function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item["Value"])
                            .text(item["Text"])
                            .appendTo($(id));
                    });
                });
            }
        }

        function bindMuXingDropDownList(id, parentid) {

            if ($(parentid).val() != "") {

                var url = "../Home/GetAreaByParent";
                $.ajaxSetup({ cache: false });
                $.getJSON(url, { id: id.substring(7), parentid: parentid.substring(7), value: $(parentid).val() }, function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item["Value"])
                            .text(item["Text"])
                            .appendTo($(id));
                    });
                });
            }
        }

        function areaDingJia() {
            $('#dlg').dialog('open');
        };
        function muxingDingJiaSave() {
            var quguid = $('#muxingqu').val();
            var price = $('#muxingprice').val();
            var muxing = $('#muxing').val();
            if (quguid == "") {
                alert("请选择区域");
                return;
            }
            if (muxing == "") {
                alert("请选择墓型");
                return;
            }
            if (price == "") {
                alert("请填写价格");
                return;
            }
            $.messager.confirm('操作提示', "确认修改价格吗？", function (r) {
                if (r) {
                    $.post("../Cemetery/MuXingDingJia", { quguid: quguid, price: price,muxing:muxing }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据
                            $.messager.alert('操作提示', '修改成功!', 'info');
                            $('#dlg').dialog('close');
                            $('#flexigridData').datagrid("reload");
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '修改失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });

        }
        function areaDingJiaSave() {
            var quguid = $('#Qu').val();
            var price = $('#price').val();
            if (quguid == "") {
                alert("请选择区域");
                return;
            }
            if (price == "") {
                alert("请填写价格");
                return;
            }
            $.messager.confirm('操作提示', "确认修改价格吗？", function (r) {
                if (r) {
                    $.post("../Cemetery/AreaDingJia", { quguid: quguid, price: price }, function (res) {
                        if (res == "OK") {
                            //移除删除的数据
                            $.messager.alert('操作提示', '修改成功!', 'info');
                            $('#dlg').dialog('close');
                            $('#flexigridData').datagrid("reload");
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '修改失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });

        }
        
        function muxingdingjia() {
            $('#muxing').empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($('#muxing'));
            var url = "../Shape/GetMuXing";
            $.ajax({
                url: url,
                type: "Post",

                dataType: "json",
                success: function (data) {
                    if (data == null) {
                        return;
                    }
                    $.each(data, function (i, item) {
                        if (item == null) {
                            return;
                        }
                        $("<option></option>")
                            .val(item["Value"])
                            .text(item["Text"])
                            .appendTo($('#muxing'));
                    });
                }
            });
            
            $('#muxingdlg').dialog('open');
        }
        function getmuxingpian(Pian) {
            $(Pian).empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($(Pian));
            bindMuXingDropDownList(Pian, "#muxingyuan");
            $(Pian).change();
        }

        function getmuxingqu(Qu) {
            $(Qu).empty();
            $("<option></option>")
                .val("")
                .text("请选择")
                .appendTo($(Qu));
            bindMuXingDropDownList(Qu, "#muxingpian");
            $(Qu).change();
        }

        function danmudingjia() {
            window.location.href = "../Cemetery/DanMuDingJia";
        }
    </script>

</asp:Content>


